#ifndef TEXTBLOCK_H_
#define TEXTBLOCK_H_

#include "LinkTemplate.h"
#include <e32base.h>
#include <Gdi.h>
#include <e32std.h>
#include "TextLineLink.h"

class TextStyle
{
public:
	CFont* iFont;
	TFontSpec iFontSpec;
	TBuf<32> iFontName;
	TBuf<32> iFontSize;
	TRgb iColor;
	TRgb iBackColor;
	TBool iBold;
	TBool iItalic;
	
private:
	TInt iRef;
public:
	TextStyle();
	virtual ~TextStyle();
	
	void AddRef();
	void RemoveRef();
	
	void SetPropertyL(const TDesC& aProperty,const TDesC& aValue);
	void SetPropertyL(const TDesC8& aProperty,const TDesC8& aValue);

};

class CTextBlock : public CBase,public IItem
{
public:
	CTextBlock();
	virtual ~CTextBlock();
	
public:
	static CTextBlock* NewL(const TDesC& aDes);
	static CTextBlock* NewLC(const TDesC& aDes);
private:
	void ConstructL(const TDesC& aDes);
	
public:
	void EstimateSize();
	void CreateFontSpecByStyleL();
	void Draw(CGraphicsContext* aGc);
	void SplitTextL(TextLineLink& aTextLineLink,TInt aWidth);
	void SplitTextL(TextLineLink& aTextLineLink,TInt aWidth,TInt aOriginStartPos);
	CTextBlock* CloneL();
	CTextBlock* CloneSubStrL(TInt aBegin,TInt aEnd,TInt aWidth,TInt aHeight);
private:
	TInt GetSubStrByWidth(TInt aBegin,TInt aWidth,TBool isNewLine,TInt& desWidth,TInt& desHeight);
public:
	TextStyle* iTextStyle;
private:
	HBufC* iText;
private:
	TRect iBlockRect;
	TInt iMaxAscent;

public:
	void SetSize(TInt aWidth,TInt aHeight);
	void SetLTPoint(TInt aLeft,TInt aTop);
	TRect GetBlockRect() const;
};

#endif /*TEXTBLOCK_H_*/
